package com.unidt.www.module.bpm.dal.mysql.definition;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.unidt.www.framework.mybatis.core.mapper.BaseMapperX;
import com.unidt.www.module.bpm.dal.dataobject.definition.ActReActConfigDo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @Author sk
 * @Description:
 * @Date 2023/2/6 18:05
 **/
@Mapper
public interface ActReActConfigMapper extends BaseMapperX<ActReActConfigDo> {



    default ActReActConfigDo getActBaseConfig(String modelId, String actId) {

        LambdaQueryWrapper<ActReActConfigDo> lambdaQueryWrapper =
                new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ActReActConfigDo::getActId, actId);
        lambdaQueryWrapper.eq(ActReActConfigDo::getModelId, modelId);
        lambdaQueryWrapper.isNull(ActReActConfigDo::getProcessDefinitionId);
        lambdaQueryWrapper.eq(ActReActConfigDo::getDeleted, false);

        return this.selectOne(lambdaQueryWrapper);
    }

    default ActReActConfigDo getProcessConfig(String processDefinitionId, String actId) {

        LambdaQueryWrapper<ActReActConfigDo> lambdaQueryWrapper =
                new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ActReActConfigDo::getActId, actId);
        lambdaQueryWrapper.eq(ActReActConfigDo::getProcessDefinitionId, processDefinitionId);
        lambdaQueryWrapper.eq(ActReActConfigDo::getDeleted, false);
        return this.selectOne(lambdaQueryWrapper);
    }

    /**
     * 功能描述: 查找最新的流程模型节点配置
     * @author sk
     * @date 2023/2/8
     * @param modelId
     * @return java.util.List<com.unidt.www.module.bpm.dal.dataobject.definition.ActReActConfigDo>
     */

    default List<ActReActConfigDo> getLastByModelId(String modelId) {
        LambdaQueryWrapper<ActReActConfigDo> lambdaQueryWrapper =
                new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ActReActConfigDo::getModelId, modelId);
        /**
         * processDefinitionId =null
         * 一个流程模型 保存一份最新的数据
         * 后续最新流程定义copy 然后再追加最新定义
         */
        lambdaQueryWrapper.isNull(ActReActConfigDo::getProcessDefinitionId);
        lambdaQueryWrapper.eq(ActReActConfigDo::getDeleted, false);
        return this.selectList(lambdaQueryWrapper);
    }

    /**
     * 功能描述: 删除配置
     * @author sk
     * @date 2023/2/8
     * @param id
     * @return void
     */

    default void deleteConfig(Long id){
        LambdaUpdateWrapper<ActReActConfigDo> lambdaUpdateWrapper =
                new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(ActReActConfigDo::getId,id);
        this.delete(lambdaUpdateWrapper);
    };
}
